package com.zhf.testpool;

import com.zhf.utils.C3P0Utils;

import java.sql.*;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/9/24 21:39
 */
public class TestC3P0 {
    public static void main(String[] args) throws SQLException {
        //获取连接
        Connection connection = C3P0Utils.getConnection();

        //获取语句执行对象
        String sql="select * from employee where ename=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        //设置占位符的值
        preparedStatement.setString(1,"李白");
        ResultSet resultSet = preparedStatement.executeQuery();

        //处理结果集
        while (resultSet.next()){
            int eid=resultSet.getInt("eid");
            String ename=resultSet.getString("ename");
            int age=resultSet.getInt("age");
            String sex=resultSet.getString("sex");
            double salary=resultSet.getDouble("salary");
            Date empdate = resultSet.getDate("empdate");
            System.out.println("eid:"+eid+"ename:"+ename+"sex:"+sex+"age:"+age+"salary:"+salary+"empdate:"+empdate);
        }

        //释放资源
        C3P0Utils.close(connection,preparedStatement,resultSet);
    }
}
